Session 4 Cheat Sheet — Quarto Documents with R
Applied Methods · MA Public Administration
1. Minimal Quarto document
A Quarto document combines YAML + Markdown + R code.
---
title: "My report"
author: "Student Name"
format: html
---
# Introduction
This is some text.
```{r}
summary(mtcars)
```Workflow: save the .qmd file → click Render → inspect the output.
2. Useful YAML options
The YAML header is written between --- lines at the top of the document.
---
title: "My report"
subtitle: "Optional subtitle"
author: "Student Name"
date: today
format:
html:
toc: true
code-fold: true
execute:
warning: false
message: false
---| Option | Purpose |
|---|---|
title |
document title |
subtitle |
optional subtitle |
author |
author name |
date: today |
current date |
format: html |
HTML output |
toc: true |
table of contents |
code-fold: true |
collapsible code |
execute: |
options applied to all R chunks |
YAML uses indentation. Options belonging to html: must be indented below it.
Other output formats
format: htmlformat: docxformat: pdfFor this course, HTML is usually the simplest option.
3. Markdown for written text
Headings
# Main section
## Subsection
### Smaller subsectionText formatting
**bold text**
*italic text*Lists
- first item
- second item
- third item1. first step
2. second step
3. third stepLinks
[Quarto documentation](https://quarto.org/docs/)Images
Control the displayed size:
{width="60%"}4. R chunks
A basic R chunk:
```{r}
summary(mtcars)
```A useful setup chunk near the beginning of the document:
```{r}
#| label: setup
#| message: false
#| warning: false
library(tidyverse)
```Main chunk options
| Option | Effect |
|---|---|
#| echo: false |
hide code, keep output |
#| eval: false |
show code, do not run it |
#| warning: false |
hide warnings |
#| message: false |
hide messages |
Example:
```{r}
#| echo: false
#| warning: false
#| message: false
summary(mtcars)
```Apply options to the whole document
Instead of repeating options in every chunk:
execute:
echo: false
warning: false
message: false5. Figures
A ggplot produced in a chunk is automatically added to the document.
```{r}
#| fig-cap: "Relationship between weight and fuel efficiency"
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point()
```Optional figure size:
```{r}
#| fig-width: 7
#| fig-height: 5
#| fig-cap: "Relationship between weight and fuel efficiency"
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point()
```6. Tables and R output
Quarto displays output produced by R.
head(mtcars)A simple summary table:
mtcars |>
summarise(
mean_mpg = mean(mpg),
mean_weight = mean(wt),
n = n()
)For more polished tables, useful packages include gt, knitr, and modelsummary.
7. A simple report structure
# Introduction
# Data
# Descriptive analysis
# Model
# Interpretation
# ConclusionA good report should combine results and written interpretation, not only code output.
8. Useful extras
Equations
Inline equation:
The mean is written as $\bar{x}$.Display equation:
$$
y_i = \beta_0 + \beta_1 x_i + \epsilon_i
$$Citations
Add a bibliography file in the YAML:
bibliography: references.bibThen cite a source:
Previous research shows this relationship [@author2024].9. Common problems
| Problem | Check |
|---|---|
| Document does not render | packages are loaded inside the .qmd |
| Object not found | object is created earlier in the document |
| Image missing | file path is correct |
| YAML error | indentation is correct |
| Too much output | use echo, warning, or message options |
| Code works in console but not when rendering | document can run from top to bottom by itself |
A reliable Quarto document should be reproducible from a fresh R session.
10. Minimal workflow to remember
1. Create a .qmd file
2. Add the YAML header
3. Structure text with Markdown
4. Add R chunks
5. Render
6. Inspect the output
7. Fix and render again
11. Documentation
You do not need to memorise every Quarto option. Look up additional features when you need them.